package com.zhouyu.postProcess;

import com.zhouyu.service.OrderService;
import com.zhouyu.service.UserService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.stereotype.Component;

/**
 * @program: spring-framework-5.3.10
 * @description: 后置处理器
 * @author: chaidl  ！
 * @create: 2021-10-08 11:15
 */
// @Component
public class CduolaiBeanPostProcessor implements MergedBeanDefinitionPostProcessor {
	/**
	 * Post-process the given merged bean definition for the specified bean.
	 *
	 * @param beanDefinition the merged bean definition for the bean
	 * @param beanType       the actual type of the managed bean instance
	 * @param beanName       the name of the bean
	 * @see AbstractAutowireCapableBeanFactory#applyMergedBeanDefinitionPostProcessors
	 */
	@Override
	public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
		// if ("userService".equals(beanName)) {
		// 	beanDefinition.getPropertyValues().add("orderService", new OrderService()); }
	}


	// @Override
	// public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
	// 	if ("userService".equals(beanName)){
	// 		System.out.println("实例化前第二次处理");
	// 	}
	// 	return false;
	// }
	//
	// @Override
	// public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
	// 	if ("userService".equals(beanName)){
	// 		System.out.println("实例化前第一次处理");
	// 		// userService这个Bean，在实例化前会直接返回一个由我们所定义的UserService对象。
	// 		// 如果是这样， 表示不需要Spring来实例化了，
	// 		// 并且后续的Spring依赖注入也不会进行了，会跳过一些步骤，直接执 行初始化后这一步.
	// 		return new UserService();
	// 	}
	// 	return null;
	// }
}
